<template>
	<div>
		<el-dialog title="选择科室" :visible.sync="depaCopy">
			<div class="departSearch clear">
				<div class="fl">药师：<span>{{real_name}}</span></div>
				<div class="fl" style="margin-left:20px;">
					<span>选择操作类型：</span>
					 <el-select v-model="state" placeholder="请选择" style="width:80px;">
					    <el-option
					      v-for="item in options"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					  </el-select>
				</div>
				<el-button type="primary" class="pop_btn fr" @click="sureFun">确认</el-button>
			</div>
			<Graytable :tHead="tHead" :tData="tData" :highlight="highlight" @currentChange="currentChange"></Graytable>
			<pagination :total="query.total" :page.sync="query.page" :limit.sync="query.limit" @pagination="getList" />
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name:"Copydepart",
		data () {
			return {
				state: 'get',
				highlight:true,
				query:{
					total:0,
					page:1,
					limit:10
				},
				options:[
					{label:"获取",value:'get'},
					{label:"赋予",value:'put'},
				],
				tHead:[
					{
						prop:"select",
						width:50,
						align:"center"
					},
					{
						prop:"ID",
						label:"唯一码"
					},
					{
						prop:"USER_NO",
						label:"药师编码"
					},
					{
						prop:"REAL_NAME",
						label:"药师名称"
					},
					{
						prop:"DEPTNAMES",
						label:"科室集合"
					},
				],
				depaCopy:false,
				tData: [],
				real_name:"",
				uid:"",
				checkbox:{}
			}
		},
		props:{
			dataObj:{
				required: true,
				type:Object
			},
			type:{
				type:String,
				default:'mz'
			}
		},
		watch:{
			dataObj(val){
				this.id=this.dataObj.id;
				this.real_name=this.dataObj.real_name;
				this.getList();
			}
		},
		methods:{
			async getList(){
				var res;
				if(this.type=="mz"){
					res=await this.$ptc.pharJsonOther({
						phar_id:this.id,
						type:"mz",
						page:this.query.page,
						pageSize:this.query.limit
					});
				}else if(this.type=="zy"){
					res=await this.$ptc.pharJsonOther({
						phar_id:this.id,
						type:"zy",
						page:this.query.page,
						pageSize:this.query.limit
					});
				}
				if(res.total>0){
					this.query.total=res.total;
					for(var i=0;i<res.rows.length;i++){
						// res.rows[i].select="<i class='iconfont iconcheck_no'>11</i>"
						res.rows[i].select="<i class='iconfont iconcheck_no' style='color:#cfcfcf;font-size:18px;'></i>"
					}
					this.tData=res.rows;
				}
				console.log(res);
			},
			show(){
				this.depaCopy=true;
			},
			hide(){
				this.depaCopy=false;
			},
			currentChange(row){
				this.checkbox=row;
				for(var i=0;i<this.tData.length;i++){
					if(row.id == this.tData[i].id){
						this.tData[i].select="<i class='iconfont iconcheck_yes' style='color:#409eff;font-size:18px;'></i>";
					}else{
						this.tData[i].select="<i class='iconfont iconcheck_no' style='color:#cfcfcf;font-size:18px;'></i>";
					}
				}
			},
			async sureFun(){
				var res;
				if(this.state == "get"){
					res=await this.$ptc.otherToMy({
						myself:this.id,
						other:this.checkbox.id,
						type:this.type
					})
				}else{
					res=await this.$ptc.myToOther({
						myself:this.id,
						other:this.checkbox.id,
						type:this.type
					})
				}
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				if(res.code == 1){
					this.checkbox={};
					this.getList();
					this.$emit("distdepaChange")
				}
			}
		}
	}
</script>

<style>
	@import url("http://at.alicdn.com/t/font_1722226_774hfks5fvu.css");
</style>
